package com.ict.web.controller.yzq;



import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.core.page.TableDataInfo;
import com.ict.common.utils.SecurityUtils;
import com.ict.web.msg.vo.SysMsgVo;
import com.ict.web.service.HomePageTotalService;
import com.ict.web.vo.NoticeAndMsgVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页统计Controller
 *
 * @author xc
 * @date 2022-3-1
 */
@Api(tags = "首页统计")
@RestController
@RequestMapping("/homePageTotal")
public class HomePageTotalController extends BaseController {

    @Autowired
    private HomePageTotalService homePageTotalService;


    /**
     * 首页-统计
     */
    @GetMapping("/homePageStatistics")
    @ApiOperation(value ="首页-统计")
    public AjaxResult homePageStatistics() {
        return AjaxResult.success(homePageTotalService.homePageStatistics());
    }
    /**
     * 待办事项list
     */
    @GetMapping("/resourceApplyAndCollect")
    @ApiOperation(value ="待办事项list")
    public AjaxResult resourceApplyAndCollect() {
        return AjaxResult.success(homePageTotalService.resourceApplyAndCollect());
    }
    /**
     * 我的消息list
     */
    @GetMapping("/msgList")
    @ApiOperation(value ="我的消息list")
    public TableDataInfo msgList(String noticeTitle) {
        startPage();
        List<SysMsgVo> list = homePageTotalService.msgList(noticeTitle);
        return getDataTable(list);
    }
    /**
     * 根据登录用户查询所有未读消息数
     */
    @GetMapping("/count")
    @ApiOperation("根据登录用户查询所有未读消息，超级管理员返回所有未读消息数")
    public AjaxResult countByUserId()
    {
        int i = homePageTotalService.countByUserId(SecurityUtils.getUserId());
        if (i<0){
            return AjaxResult.error();
        }
        if (i>99){
            return AjaxResult.success("操作成功","99+");
        }
        return AjaxResult.success(i);
    }
    /**
     * 根据通知id修改通知状态为已读
     */
    @PutMapping("/update/{id}")
    @ApiOperation("根据通知id修改通知状态为已读")
    public AjaxResult update(@PathVariable("id") String id)
    {
        return toAjax(homePageTotalService.updateReadFlagById(id));
    }
}
